"""
组成基本参数组件的单个组件
包括：
    1.滑动条
    2.单行编辑栏
    3.多行编辑栏
    4.下拉菜单栏
    5.复选框
    6.独立按钮选项
    7.基本按钮
    8.文件按钮


"""
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from ..cgai import CGAI




class CGAISlider(QSlider):
    """
    滑动条
    """
    def __init__(self,orientation):
        super(CGAISlider, self).__init__()
        self.setOrientation(orientation)
        self.setStyleSheet('''
        QSlider::groove:horizontal {border: 0px solid #696969;}
        QSlider::sub-page:horizontal {background: #ff6600 ;border-radius: 0px;margin-top: 8px;margin-bottom: 9px}
        QSlider::add-page:horizontal {background: #1C1C1C;border: 0px solid #777;border-radius: 2px;margin-top: 8px;margin-bottom: 9px}
        QSlider::handle:horizontal {background: #B5B5B5;border: 1px solid rgba(102,102,102,102);width: 8px;height: 8px;border-radius: 5px;margin-top: 2px;margin-bottom: 2px}
        QSlider::handle:horizontal:hover {background: #ff6600;border: 1px solid rgba(102,102,102,102);border-radius: 5px}
        QSlider::sub-page:horizontal:disabled {background: #bbb;border-color: #999}
        QSlider::add-page:horizontal:disabled {background: #eee;border-color: #999}
        QSlider::handle:horizontal:disabled {background: #eee;border: 1px solid #aaa;border-radius: 4px}
      ''')

    def mousePressEvent(self, QMouseEvent):
        if QMouseEvent.button() ==Qt.LeftButton:
            e_pos = QMouseEvent.pos()
            x=e_pos.x()
            all_count= self.maximum() -self.minimum()
            pos =self.minimum() + all_count*x/self.width()
            if pos != self.sliderPosition():
                self.setValue(pos)
        super(CGAISlider, self).mousePressEvent(QMouseEvent)

class CGAIEdit(QLineEdit):
    """
    单行编辑栏
    """
    def __init__(self):
        super(CGAIEdit, self).__init__()
        # self.setFixedWidth(150)
        p=self.palette()
        p.setColor(QPalette.Base,QColor('#1C1C1C'))
        p.setColor(QPalette.Text,QColor('#E8E8E8'))

        self.setStyleSheet('''
        QLineEdit{border: 0px}
        QLineEdit{background: #1C1C1C}
        ''')
        self.setPalette(p)


class CGAIMultEdit(QTextEdit):
    """
    单行编辑栏
    """
    def __init__(self):
        super(CGAIMultEdit, self).__init__()

        p=self.palette()
        p.setColor(QPalette.Base,QColor('#1C1C1C'))
        p.setColor(QPalette.Text,QColor('#E8E8E8'))

        self.setStyleSheet('''
        QLineEdit{border: 0px}
        QLineEdit{background: #1C1C1C}
        ''')
        self.setPalette(p)


class CGAIMenu(QComboBox):

    def __init__(self):
        super(CGAIMenu, self).__init__()
        p=self.palette()
        p.setColor(QPalette.Button,QColor('#1C1C1C'))
        p.setColor(QPalette.Text,QColor('#E8E8E8'))
        # self.setFixedWidth(55)
        self.setMinimumWidth(55)
        self.setView(QListView())
        self.setStyleSheet('''
                  QComboBox QAbstractItemView::item{height:35px;background: #1C1C1C;color:#E8E8E8 }
          QComboBox{border: 0px}
          QComboBox{background: #1C1C1C;color:#E8E8E8}

          QComboBox{font-size:%dpx}
          ''' % CGAI.PARM_LIST_FONT_SIZE)
        self.setPalette(p)
